<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\User;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class UserController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new User(), function (Grid $grid) {
            $grid->model()->orderByDesc('id');
            $grid->column('id')->sortable();
            $grid->column('name');
            $grid->column('mobile');
            $grid->column('avatar')->image("", 45, 45);
            $grid->column('gender')->display(function ($gender) {
                $user = new User();
                return $user->getGenderList($gender);
            })->filter(
                Grid\Column\Filter\In::make((new User())->getGenderList())
            );
            $grid->column('birthday');
//            $grid->column('bio');
//            $grid->column("pid");
//            $grid->column('invite_code');
            $grid->column('money');
            $grid->column('earning');
//            $grid->column('province');
            $grid->column('city');
//            $grid->column('area');
//            $grid->column('email');
//            $grid->column('email_verified_at');
//            $grid->column('password');
//            $grid->column('remember_token');
            $grid->column('xinli');
            $grid->column('zhanbu');
            $grid->column('qingting');
//            $grid->column('like_num');
            $grid->column('status')->switch();
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
            });
            $grid->disableEditButton();
            $grid->disableCreateButton();
            $grid->disableDeleteButton();
            $grid->toolsWithOutline(false);

        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new User(), function (Show $show) {
            $show->field('id');
            $show->field('avatar');
            $show->field('name');
            $show->field('gender');
            $show->field('birthday');
            $show->field('bio');
            $show->field('intro');
            $show->field('invite_code');
            $show->field('money');
            $show->field('earning');
            $show->field('province');
            $show->field('city');
            $show->field('area');
//            $show->field('email');
//            $show->field('email_verified_at');
            $show->field('password');
//            $show->field('remember_token');
            $show->field('xinli');
            $show->field('zhanbu');
            $show->field('qingting');
            $show->field('like_num');
            $show->field('status');
            $show->field('mobile');
            $show->field('created_at');
            $show->field('updated_at');
            $show->disableEditButton();
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new User(), function (Form $form) {
            $form->display('id');
            $form->text('mobile');
            $form->text('name');
            $form->image('avatar');
            $form->text('gender');
            $form->text('birthday');
            $form->text('bio');
//            $form->text('invite_code');
            $form->text('money');
            $form->text('earning');
            $form->text('province');
            $form->text('city');
            $form->text('area');
//            $form->text('email');
//            $form->text('email_verified_at');
            $form->text('password');
//            $form->text('remember_token');
            $form->text('xinli');
            $form->text('zhanbu');
            $form->text('qingting');
            $form->text('like_num');
            $form->text('status');

//            $form->display('created_at');
//            $form->display('updated_at');
        });
    }
}
